feat(oracles/pyth): add pinocchio example - #707
Conversation
Greptile SummaryThe PR adds a Pinocchio implementation of the Pyth oracle example.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported malformed verification-level acceptance is fixed by rejecting every discriminant other than the two supported variants before reading price fields. Important Files Changed
Reviews (3): Last reviewed commit: "test(oracles/pyth): cover the real feed ..." | Re-trigger Greptile |
b89fd70 to
d5c713d
Compare
Adds a Pinocchio implementation of the Pyth oracle example, the first pinocchio example under oracles/. The single read_price instruction reads a Pyth pull oracle PriceUpdateV2 account and logs its price fields. There is no Pyth SDK for Pinocchio, so the account is parsed by hand: the program checks the account's owner (the Pyth receiver program) and the anchor account discriminator before trusting the data, then reads the price, confidence, exponent, and publish time by byte offset. The account's VerificationLevel is a variable-size Borsh enum, so the price message offset is computed from it. The litesvm test injects a mock PriceUpdateV2 account with known values via setAccount and asserts the program logs the parsed fields, plus a second case that a non-Pyth-owned account is rejected.
d5c713d to
0e328ad
Compare
…offset The mock accounts are built by the same code that the assertions trust, so they stay self-consistent even if the layout drifts from what Pyth writes. Adds prepare.mjs, which dumps the mainnet SOL/USD price update, and a test that decodes the price out of those bytes in TypeScript and asserts the program logs the same value. `encodePriceUpdate` also wrote the price message at the `Full` offset whatever verification level it was given, so a `Partial` account it built was internally inconsistent and the program's dynamic offset went untested. It now honours the level, and a new test reads back a partially verified update whose message really does sit one byte later.
|
Pushed two test additions. No program changes. A real mainnet feed, not just mocks. The partial-verification offset was untested.
|
|
@amilz could you take a look at this one when you get a chance? No open review threads left on it, so it is ready for maintainer review. It is one of 23 open Pinocchio ports I have up — they are independent and self-contained, so they can be reviewed and merged in any order: https://github.com/solana-developers/program-examples/pulls/MarkFeder |
What
Adds a Pinocchio implementation of the Pyth oracle example (the first pinocchio example under
oracles/), alongside the existinganchorversion. A singleread_priceinstruction reads a Pyth pull-oraclePriceUpdateV2account and logs its price fields.How it works
There is no Pyth SDK for Pinocchio, so the account is parsed by hand:
rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ) and its 8-byte anchor discriminator — so the program never trusts the price data of an arbitrary account (what anchor'sAccount<PriceUpdateV2>does for free).PriceFeedMessage: it follows the discriminator (8), write authority (32), and theVerificationLevel. That enum is variable-size (Full= 1 byte,Partial { num_signatures }= 2), so the message offset is computed from it.price(i64),conf(u64),exponent(i32), andpublish_time(i64) by little-endian byte offset and log them.Test
litesvm+@solana/kit. Since litesvm doesn't bundle Pyth, the test constructs a mockPriceUpdateV2account with known values and injects it viasetAccount, then:price/conf/exponent/publish_time, andVerified locally:
cargo build-sbf, the litesvm tests,tsc --noEmit, Prettier,cargo fmt --check, Clippy, andpnpm install --frozen-lockfileall clean. (Thedeployscript uses the*.soglob per #702.)AI use: I chose the approach (hand-parsing the
PriceUpdateV2layout, validating owner + discriminator, the mock-account test) and verified the layout and discriminator against thepyth-solana-receiver-sdk/pythnet-sdksources; implementation and tests were written with Claude Code and reviewed by me.